package com.uzhie.web.service.listener;

import org.apache.activemq.command.ActiveMQDestination;
import org.apache.log4j.Logger;
import org.springframework.jms.core.JmsTemplate;

import javax.jms.BytesMessage;

/**
 * Created by zhenghao on 2017/7/4.
 */
public class MQPositionSendService implements MQSendService {

    private JmsTemplate jmsTemplate;

    private ActiveMQDestination mqDestination;

    public void setJmsTemplate(JmsTemplate jmsTemplate) {
        this.jmsTemplate = jmsTemplate;
    }

    public void setMqDestination(ActiveMQDestination mqDestination) {
        this.mqDestination = mqDestination;
    }

    /**
     * 根据不同类型 向不同的队列发送信息
     *
     * @param queue
     * @param ID
     * @param body
     */
    @Override
    public void sendMessage(Integer queue, final String ID, final byte[] body) {
        jmsTemplate.send(mqDestination, session -> {
            BytesMessage message = session.createBytesMessage();
            message.setStringProperty("simNumber", ID);
            message.writeBytes(body);
            return message;
        });
        LOGGER.info("向队列" + mqDestination.toString());
        LOGGER.info("发送定位消息 sim卡号-------->" + ID);
        LOGGER.info("消息体内容 -------->" + body);
    }

}
